#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int n;
int a[N],qzh[N];
struct VALUE{int x,y;};
inline VALUE max(VALUE x,VALUE y){
	if(x.x*y.y<y.x*x.y){
		return y;
	}
	else return x;
}
VALUE st[N][22];
int lg[N];
inline VALUE query(int l,int r){
	if(l>r) return {LONG_LONG_MIN,1};
	int k=lg[r-l+1];
	return max(st[l][k],st[r-(1<<k)+1][k]);
}
int sta[N],id[N],tp;
signed main(){
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	n=read();
	For(i,1,n) a[i]=read(),qzh[i]=qzh[i-1]+a[i];
	For(i,2,n) lg[i]=lg[i/2]+1;
	int Q=read();
	int B=80;
	For(i,1,n){
		int x=0;
		VALUE p={LONG_LONG_MIN,1};
		For(j,1,B){
			if(i+j-1>n) break;
			x+=a[i+j-1];
			p=max(p,{x*x,j});		
		}
		st[i][0]=p;
	}
	For(j,1,19){
		For(i,1,n){
			st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
	while(Q--){
		int l=read(),r=read();
		VALUE res=query(l,max(r-B,l-1));
		For(i,max(r-B,l-1)+1,r){
			int x=0;
			For(j,i,r){
				x+=a[j];
				res=max(res,{x*x,j-i+1});
			}
		}
		int p=__gcd(res.x,res.y);
		res.x/=p;
		res.y/=p;
		printf("%lld %lld\n",res.x,res.y);
	}
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

